﻿
package com.ostrich.manpower.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.service.BaseService;
import com.ostrich.manpower.bean.TostHrDepartinfo;
import com.ostrich.manpower.common.MathPageno;
import com.ostrich.manpower.service.TostHrDepartinfoDao;
/**
 * @author wangyinan
 * @brief    模块功能简单描述
 * @details  模块功能详细描述
 */
@Service("tostHrDepartinfoService")
public class TostHrDepartinfoService<T> extends BaseService<T> {
	private final static Logger log= Logger.getLogger(TostHrDepartinfoService.class);

	@Autowired
    private TostHrDepartinfoDao<T> dao;

	public TostHrDepartinfoDao<T> getDao() {
		return dao;
	}
	//查询所属部门
	public java.util.List<TostHrDepartinfo> queryDapart(){
		java.util.List<TostHrDepartinfo> list=new ArrayList<TostHrDepartinfo>();
		list=dao.queryDepartId();
		return list;
	}
	
	/***
	 * 添加部门信息
	 * @param t
	 * @throws Exception
	 */
	public void addDept(TostHrDepartinfo t)  throws Exception{
		TostHrDepartinfo td=(TostHrDepartinfo)t;
		if(td!=null){
		String pid=(td.getHdpPid()==null ||td.getHdpPid().length()<=0 || td.getHdpPid()=="null")?"":td.getHdpPid();
		String parm = (td.getHdpPid()!=null && td.getHdpPid().trim().length()==0)?null:td.getHdpPid();
		
		String nextid=MathPageno.getIdNextII(pid, getMaxByHdpPid(parm));
		td.setId(nextid);
		dao.addDept(td);
		}else{
			dao.update(td);
		}
	}
	
	
	
	//获取父节点的最大id值
		public String getMaxByHdpPid(String hdpPid){
			return dao.queryMaxIdByPid(hdpPid);
		}
		//根据名字取id
		public String queryDpartidByname(String str){
			return  dao.queryDpartidByname(str);
		}
		
		public  Map<String, TostHrDepartinfo> queryDepartAllMapKeyName(){
			List<TostHrDepartinfo> depart =  (List<TostHrDepartinfo>) dao.queryByAll();
			 Map<String, TostHrDepartinfo> namemap = new HashMap<String,TostHrDepartinfo>();
			for(TostHrDepartinfo td:depart){
				namemap.put(td.getHdpName(),td);
			}
			return namemap;
		}
		//根据你id找名字
		public String querydnameByid(String id){
			return getDao().querydnameByid(id);
		}
		//根据id查询类型 36绩效，37提成。
		public String queryTypeByid(String id){
			return getDao().queryTypeByid(id);
		}
		
		public List<T> queryDepartName(String dpids){
			return getDao().queryDepartName(dpids);
		}
}
